package bdd.daos.impl;

import bdd.DBLink;
import java.util.List;

import bdd.daos.*;
import beans.Etudiant;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class DAOEtudiantImpl implements DAOEtudiant {
    private DBLink dblink;

    public DAOEtudiantImpl() {
		this.dblink = new DBLink();
		this.dblink.connexion();
    }

	public Etudiant save(Etudiant o) {
		return null;
	}

	@Override
	public Etudiant find(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Etudiant> findAll() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void update(Etudiant transientObject) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(Etudiant persistentObject) {
		// TODO Auto-generated method stub

	}

    public List<Etudiant> findByPromotion(Integer numPromotion) {
        List<Etudiant> Lstretour = new ArrayList<Etudiant>();
        try
        {
            String rq = "select numEtudiant "
                    + "from JNTETUDIANTPROMOTION "
                    + "where numpromotion = " + numPromotion
                    + "  order by numEtudiant";
            this.dblink.connexion();
            this.dblink.setPst(this.dblink.getConnection().prepareStatement(rq));
            ResultSet rs = this.dblink.getPst().executeQuery();
            while(rs.next()) {
				Etudiant retour = new Etudiant();
                                retour.setNumetudiant(rs.getInt("numEtudiant"));

				Lstretour.add(retour);
			}
		}
		catch(SQLException se) {
			System.out.println("Erreur de requête" + se);
		}
		finally{
			this.dblink.deconnexion();
		}
		return Lstretour;
    }


}
